using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

using SharpCore.Data;

namespace TF.Access {
	public partial class Tf_album {
		#region Fields
		private int id;
		private string album_name;
		private int owner_id;
		private DateTime keyin_date = System.Data.SqlTypes.SqlDateTime.MinValue.Value;
		private string memo;
		#endregion
		
		#region Constructors
		/// <summary>
		/// Initializes a new instance of the Tf_album class.
		/// </summary>
		public Tf_album() {
		}
		
		/// <summary>
		/// Initializes a new instance of the Tf_album class.
		/// </summary>
		public Tf_album(string album_name, int owner_id, DateTime keyin_date, string memo) {
			this.album_name = album_name;
			this.owner_id = owner_id;
			this.keyin_date = keyin_date;
			this.memo = memo;
		}
		
		/// <summary>
		/// Initializes a new instance of the Tf_album class.
		/// </summary>
		public Tf_album(int id, string album_name, int owner_id, DateTime keyin_date, string memo) {
			this.id = id;
			this.album_name = album_name;
			this.owner_id = owner_id;
			this.keyin_date = keyin_date;
			this.memo = memo;
		}
		#endregion
		
		#region Properties
		/// <summary>
		/// Gets or sets the Id value.
		/// </summary>
		public int Id {
			get { return id; }
			set { id = value; }
		}
		
		/// <summary>
		/// Gets or sets the Album_name value.
		/// </summary>
		public string Album_name {
			get { return album_name; }
			set { album_name = value; }
		}
		
		/// <summary>
		/// Gets or sets the Owner_id value.
		/// </summary>
		public int Owner_id {
			get { return owner_id; }
			set { owner_id = value; }
		}
		
		/// <summary>
		/// Gets or sets the Keyin_date value.
		/// </summary>
		public DateTime Keyin_date {
			get { return keyin_date; }
			set { keyin_date = value; }
		}
		
		/// <summary>
		/// Gets or sets the Memo value.
		/// </summary>
		public string Memo {
			get { return memo; }
			set { memo = value; }
		}
		#endregion
		
		#region Methods
		/// <summary>
		/// Saves a record to the tf_album table.
		/// </summary>
		public void Insert() {
			id = Convert.ToInt32(SqlClientUtility.ExecuteScalar("tf_albumInsert", album_name, owner_id, keyin_date, memo));
		}
		
		/// <summary>
		/// Updates a record in the tf_album table.
		/// </summary>
		public void Update() {
			SqlClientUtility.ExecuteNonQuery("tf_albumUpdate", id, album_name, owner_id, keyin_date, memo);
		}
		
		/// <summary>
		/// Deletes a record from the tf_album table by its primary key.
		/// </summary>
		public void Delete() {
			SqlClientUtility.ExecuteNonQuery("tf_albumDelete", id);
		}
		
		/// <summary>
		/// Selects a single record from the tf_album table.
		/// </summary>
		public static Tf_album Select(int id) {
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("tf_albumSelect", id)) {
				if (dataReader.Read()) {
					return MakeTf_album(dataReader);
				} else {
					return null;
				}
			}
		}
		
		/// <summary>
		/// Selects all records from the tf_album table.
		/// </summary>
		public static List<Tf_album> SelectAll() {
			using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader("tf_albumSelectAll")) {
				List<Tf_album> tf_albumList = new List<Tf_album>();
				while (dataReader.Read()) {
					Tf_album tf_album = MakeTf_album(dataReader);
					tf_albumList.Add(tf_album);
				}
				return tf_albumList;
			}
		}
		
		/// <summary>
		/// Creates a new instance of the tf_album class and populates it with data from the specified SqlDataReader.
		/// </summary>
		private static Tf_album MakeTf_album(SqlDataReader dataReader) {
			Tf_album tf_album = new Tf_album();
			
			if (dataReader.IsDBNull(0) == false) {
				tf_album.Id = dataReader.GetInt32(0);
			}
			if (dataReader.IsDBNull(1) == false) {
				tf_album.Album_name = dataReader.GetString(1);
			}
			if (dataReader.IsDBNull(2) == false) {
				tf_album.Owner_id = dataReader.GetInt32(2);
			}
			if (dataReader.IsDBNull(3) == false) {
				tf_album.Keyin_date = dataReader.GetDateTime(3);
			}
			if (dataReader.IsDBNull(4) == false) {
				tf_album.Memo = dataReader.GetString(4);
			}

			return tf_album;
		}
		#endregion
	}
}
